const KoaRouter = require('koa-router')
const storeService = require('../service/storeService')
const code = require('../common/code')
const auth = require('../middleware/auth')

const router = new KoaRouter()

router.get('/store', auth(['EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await storeService.getStore(ctx.session.user.store_id))
})

router.put('/store', auth(['EDP']), async ctx => {
    await storeService.updateStore(ctx.session.user.store_id, ctx.request.body)
    ctx.body = code.getCode(code.SUCCESS)
})

module.exports = router
